CREATE TABLE [dbo].[RFMDefinition]
(
[RFMKey] [uniqueidentifier] NOT NULL,
[Name] [nvarchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Description] [nvarchar] (500) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[UserDocumentKey] [uniqueidentifier] NULL,
[TransactionDocumentKey] [uniqueidentifier] NULL,
[IsAutoMode] [bit] NOT NULL,
[NumRecency] [int] NULL,
[NumFrequency] [int] NULL,
[NumMonetary] [int] NULL,
[DateExecuted] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RFMDefinition] ADD CONSTRAINT [PK_RFMDefinition] PRIMARY KEY CLUSTERED ([RFMKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RFMDefinition_TransactionDocumentKey] ON [dbo].[RFMDefinition] ([TransactionDocumentKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_RFMDefinition_UserDocumentKey] ON [dbo].[RFMDefinition] ([UserDocumentKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[RFMDefinition] ADD CONSTRAINT [FK_RFMDefinition_DocumentMain_Transaction] FOREIGN KEY ([TransactionDocumentKey]) REFERENCES [dbo].[DocumentMain] ([DocumentKey])
GO
ALTER TABLE [dbo].[RFMDefinition] ADD CONSTRAINT [FK_RFMDefinition_DocumentMain_User] FOREIGN KEY ([UserDocumentKey]) REFERENCES [dbo].[DocumentMain] ([DocumentKey])
GO